Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
Trying to use a mongoDB query to populate a select menu, results in "Objects are not valid as a React child (found: [object Promise])."

Here's what I'm trying to do: I call a mongoDB distinct query using axios.get in order to find various provinces people are in, then put as options for a select menu, to allow a user to search for a person based on province.

But when I try to use this, the website crashes and gives me the error "Error: Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead."

Another error it gives is that "type.map" is not a function. Possibly related to the above error?

How do I fix this?

import * as React from "react";
import axios from "axios";
 
export default async function Locations() {

  let options = null;

  async function axiosTest() {
    // This is a server link i created that runs a query that returns distinct provinces from the database
    axios.get("/api/v2/people/provinces").then(data => console.log(data));
    return await axios.get("/api/v2/people/provinces");
    // The console.log() above displays all the objects that are in the query given by the server link in an array
    // e.g. ['British Columbia', 'Alberta', 'Saskatchewan', etc.]
  }
  
  var type = await axiosTest();

  if (type) {
    options = type.map((el) => <option key={el}>{el}</option>);
  }

  return (
    <div
      style={{
        padding: "16px",
        margin: "16px",
      }}
    >
      <form>
        <div>
          <select>
            {
              options
            }
          </select>
        </div>
      </form>
    </div>
  );
};
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!